/* File Name: demo.cpp
 * Author: Adam
 * Description: use to test the DB Operator
 * 
 * Added in my home.
 */
#include <winsock.h>
#include <iostream>
#include <mysql.h>
#include "ItemType.h"

using namespace std;

int main(void)
{
	MYSQL mysql;
	MYSQL_RES *result;
	MYSQL_ROW row;
	MYSQL_FIELD *field;
	
	mysql_init(&mysql);

	if(!mysql_real_connect(&mysql, "localhost", "admin", "admin", "node", 3306, 0, CLIENT_MULTI_STATEMENTS))
	{
		cout << "Connect error" << endl;
	}
	
	/*if(!mysql_select_db(&mysql, "node"))
	{
		cout << mysql_error(&mysql) << endl;
		cout << "select db error" << endl;
	}*/

	
	mysql_query(&mysql, "SET NAMES gbk;");

	mysql_query(&mysql, "SELECT * FROM tree LIMIT 10;");
	

	cout << mysql_field_count(&mysql) << endl;
	//int count = mysql_affected_rows(&mysql);
	
	/*if(count>0)
	{
		result = mysql_store_result(&mysql);
	}
	else
	{
		return 1;
	}*/
	result = mysql_store_result(&mysql);
	while(field = mysql_fetch_field(result))
	{
		cout << /*field->  <<*/ field->name << endl;
		
	}
	cout << mysql_affected_rows(&mysql) << endl;
	while(row = mysql_fetch_row(result))
	{
		cout << row[2] << endl;
	}
	mysql_free_result(result);
	mysql_close(&mysql);
	cout << ITEMTYPE::TABLE << endl;
	return 0;
}